package com.xiaoyu.base.config;


import android.text.TextUtils;

import com.xiaoyu.base.AppConfig;
import com.xiaoyu.base.BaseConstants;
import com.xiaoyu.base.utils.SharedPreferencesData;

import in.srain.cube.util.StringUtil;

import in.srain.cube.util.Env;

public class HttpConfig {
    private static final String DEV_MODE_HOST = SharedPreferencesData.basic() == null ? "" : SharedPreferencesData.basic().getString(BaseConstants.SharedPreferencesKey.KEY_DEV_MODE_HOST, "");

    private static String sHost = Env.isDevOrInDevMode() && !TextUtils.isEmpty(DEV_MODE_HOST) ? DEV_MODE_HOST : AppConfig.host();

    public static String getHost() {
        return sHost;
    }

    public static void setHost(String host) {
        sHost = StringUtil.defaultIfEmpty(DEV_MODE_HOST, host);
    }

    public static final String SCHEME = "https";
    public static final String BASE_URL = String.format("%s://%s", SCHEME, sHost);

    private static final String API_PREFIX = "/api";
    private static final String CALLBACK_PREFIX = "/callback";
    private static final String BASE_API_URL = BASE_URL + API_PREFIX;
    private static final String BASE_CALLBACK_URL = BASE_URL + CALLBACK_PREFIX;

    public static final String WEEX_SCHEME = "weex";
    public static final String BASE_WEEX_URL = String.format("%s://%s", WEEX_SCHEME, sHost);

    public static final int TIMEOUT = 20000;

    public static final String BASE_GENESIS_CONFIG = String.format("https://%s/api/util/genesis-config", AppConfig.genesisConfigHost());
    public static final String BASE_GLOBAL_CONFIG = String.format("https://%s/api/util/global-config-v1", AppConfig.genesisConfigHost());

    public static final String APP_LOGIN_REG_SMS = BASE_API_URL + "/app/login-reg-sms";
    public static final String APP_QINIU_TOKEN = BASE_API_URL + "/app/qiniu-token";

    public static final String USER_REFRESH_TOKEN = BASE_API_URL + "/user/refresh-token";
    public static final String USER_GET_USER_BASIC_INFO = BASE_API_URL + "/user/get-users-basic-info";
    public static final String USER_LOCK_MESSAGE = BASE_CALLBACK_URL + "/user/lock-message";

    public static final String UTIL_GET_REMOTE_CONFIG = BASE_API_URL + "/util/get-remote-config";
    public static final String EVENT_READ = BASE_API_URL + "/event/read";

    public static String getWeexHttpUrlForPath(String path) {
        return BASE_API_URL + "/" + path;
    }
}

